package com.logisticsinquiry.android.logic.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.logisticsinquiry.android.logic.dao.ShipperCodeResponseHistoryDao
import com.logisticsinquiry.android.logic.dao.UserDao
import com.logisticsinquiry.android.logic.entity.ShipperCodeResponseHistory
import com.logisticsinquiry.android.logic.entity.User

@Database(version = 3, entities = [ShipperCodeResponseHistory::class, User::class])
abstract class AppDatabase : RoomDatabase() {

    abstract fun shipperCodeResponseHistoryDao(): ShipperCodeResponseHistoryDao

    abstract fun userDao():UserDao
    companion object{


        private var instance: AppDatabase? = null

        @Synchronized
        fun getDatabase(context: Context):AppDatabase {
            instance?.let {
                return it
            }
            return Room.databaseBuilder(context.applicationContext,
                AppDatabase::class.java, "app_database")
                .allowMainThreadQueries()
                .build().apply {
                    instance = this
                }
        }
    }
}
